﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace FairFare
{
    public partial class Auto : PhoneApplicationPage
    {
        double dist = 0.0F;
        double rem = 0.0F;
        double fare = 0.0;
        public Auto()
        {
            InitializeComponent();
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
        }

        //Not being used (Why would a user tap the Auto Tab when he is on Auto Tab already)
        private void AutoTab_Tap(object sender, GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Auto.xaml", UriKind.Relative));
        }

        private void TaxiTab_Tap(object sender, GestureEventArgs e)
        {
            string data = textBox1.Text;
            if (data != null)
                NavigationService.Navigate(new Uri("/Taxi.xaml?name=" + data, UriKind.Relative));
            else
                NavigationService.Navigate(new Uri("/Taxi.xaml" , UriKind.Relative));
        }

        private void MetroTab_Tap(object sender, GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Metro.xaml", UriKind.Relative));
        }

        private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
        {
           
            if (textBox1.Text.Trim().Length == 0)
            {
                dist = 0.0;
            }

            else
            {
                dist = float.Parse(textBox1.Text);
            }

            if (dist <= 0.0)
            {
                fare = 0.0;
                textBox3.Text = Convert.ToString(fare);
            }

            if (dist <= 2.0 && dist >0.0)
            {
                fare = 19.0;
                if ((bool)night_charge_on.IsChecked)
                {
                    fare = fare + (fare / 4);  //25% EXTRA CHARGE FOR NIGHT.
                }
                textBox3.Text = Convert.ToString(fare);
            }

            if (dist > 2.0)
            {
                rem = dist - 2.0;
                fare = 19.0 + (rem * 6.5);

                if ((bool)night_charge_on.IsChecked)
                {
                    fare = fare + (fare / 4);  //25% EXTRA CHARGE FOR NIGHT.
                }

                textBox3.Text = Convert.ToString(fare);
            }

        }

        private void button1_Tap(object sender, GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Autoinfo.xaml", UriKind.Relative));
        }

       

      /*  private void night_charge_on_Checked(object sender, RoutedEventArgs e)
        {
           // TextChangedEventArgs e2 = (TextChangedEventArgs) textBox1 ;
            textBox1_TextChanged(textBox1, e2 );
        }*/
        
        
        
        
        
        /*private void night_charge_on_Checked(object sender, RoutedEventArgs e)
        {
            night_charge_off.IsChecked = false;
            night_charge_on.IsChecked = true;
        }

        private void night_charge_off_Checked(object sender, RoutedEventArgs e)
        {
            night_charge_on.IsChecked = false;
            night_charge_off.IsChecked = true;
            
        }*/

       /* private void night_charge_tap(object sender, GestureEventArgs e)
        {
            if ((bool)night_charge.IsChecked)
            {
                night_charge.IsChecked = false;
                night_charge.Content = "OFF";
                night_charge.
            }

            else 
            {
                night_charge.IsChecked = true;
                night_charge.Content = "ON";
            }
            
        }*/

    }
}